﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;

namespace RookieLibSharp.Ui
{
    [ToolboxBitmap(typeof(RichTextBox))]
    public class CustomRichTextBox:System.Windows.Forms.RichTextBox
    {
        const int DBCLCIK = 0x0203;//双击
        const int GETFOCUS = 0x0007;//得到焦点

        private bool _EnabledFocus;
        public CustomRichTextBox() : base()
        {

        }

#region 属性
        /// <summary>
        /// 设置控件是否获取焦点
        /// </summary>
        [DefaultValue(true)]
        public bool EnabledFocus
        {
            get { return _EnabledFocus; }
            set
            {
                _EnabledFocus = value;
                base.Invalidate();
            }
        }

#endregion
        
        
        protected override void WndProc(ref Message msg)
        {
            if (!_EnabledFocus)
            {
                if (msg.Msg == DBCLCIK || msg.Msg == GETFOCUS)
                {
                    return;
                }
            }

            base.WndProc(ref msg);
        } 
    }
}
